package com.huo.thread.synchronizeddemo;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SequenceDemo3 {

    private  int value;

    private Lock lock = new ReentrantLock();

    private  int getNext(){
        lock.lock();
       value ++;
        lock.unlock();
        return value;
    }

    public static void main(String[] args) {
        SequenceDemo3 s = new SequenceDemo3();
            for(int i = 0 ; i < 3 ; i++){


            new Thread(new Runnable() {
                @Override
                public void run() {
                    while (true) {
                        System.out.println(Thread.currentThread().getName() + ":" + s.getNext());
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }).start();
            }

    }
}
